from 快排 import quick_sort


def bucket_sort(nums, bucket_size=5):
    if len(nums) == 0:
        return nums
    min_val, max_val = min(nums), max(nums)
    bucket_count = ((max_val - min_val) // bucket_size) + 1
    buckets = [[] for _ in range(int(bucket_count))]

    # 分配到桶
    for num in nums:
        index = int((num - min_val) // bucket_size)
        buckets[index].append(num)

    # 桶内排序（使用插入排序）
    sorted_nums = []
    for bucket in buckets:
        sorted_nums.extend(quick_sort(bucket))  # 插入排序或其他算法
    return sorted_nums


if __name__ == '__main__':
    nums = [5, 5, 4, 3, 2, 1]
    r = bucket_sort(nums)
    print(r)
